﻿using UnityEditor;
using UnityEngine;


namespace XFGameFramework.Localization
{
    public class ImageWindow : EditorWindow
    {
        private Texture target;

        private GUIContent image;

        private void Awake()
        {
            titleContent = new GUIContent("查看图片");
        }

        public void SetTarget(Texture texture2d) 
        {
            this.target = texture2d;    
        }

        private void OnEnable()
        {
            target = null;
        }

        private void OnGUI()
        {
            if (target == null) 
                return; 

            if (image == null) {
                image = new GUIContent(); 
            }
            if(image.image != target)
                image.image = target;

            GUILayout.BeginHorizontal();

            GUILayout.FlexibleSpace();

            GUILayout.Label(image,GUILayout.ExpandWidth(true),GUILayout.ExpandHeight(true));

            GUILayout.FlexibleSpace();

            GUILayout.EndHorizontal();
        }

    }

}

